import { reqCode } from "../api";
import { promise } from "ora";

// 登录注册的组件
const state = {
  code: ""
};
const mutations = {
  GETCODE(state, code) {
    state.code = code;
  }
};

const actions = {
  //获取验证码
  async getCode({ commit }, phone) {
    let result = await reqCode(phone);
    console.log(result);
    //前端工程师：没有能力把验证码发到用户手机上的功能
    //务必、一定是是后台人员实现
    if (result.code === 200) {
      commit("GETCODE", result.data);
      return "ok";
    } else {
      return Promise.reject(new Error("faiile"));
    }
  }
};
const getters = {};

export default {
  state,
  mutations,
  actions,
  getters
};
